/**
 *Express.js基本示例 
 */
// 导入Express模块
const express=require("express");
// 导入session模块
const session=require("express-session");
// 创建express应用
const app=express();

// Express http服务端口
const port=3001;
//使用session中间件
app.use(session({
    secret:"secret key",
    resave:false,
    saveUninitialized:false,
}));

// http访问路径
app.get("/",function(req,res){
    let body = "";
    if(req.session.view){
        req.session.view +=1;
    }else{
        req.session.view = 1;
        body += `<p>第一次访问</p>`;
    }
    res.send(`${body} <p> 已访问<strong>${req.session.view}</strong>次</p>`);
});

// 启动Express服务
app.listen(port,function(){
    console.log(`Myapp访问地址:http://127.0.0.1:${port}`);
});